package com.yiyang.controller;

import com.yiyang.domain.dto.BedDetailsDto;
import com.yiyang.domain.po.BedDetails;
import com.yiyang.domain.vo.BedDetailVo;
import com.yiyang.service.BedDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yiyang.domain.Result;
import com.yiyang.domain.ResultPage;

import java.text.ParseException;

@RestController
@RequestMapping("/beddetails")
@Api(tags = "床位详情相关接口")
public class BedDetailController {
    @Autowired
    private BedDetailsService bedDetailService;
    @ApiOperation("床位详情的分页动态查询")
    @GetMapping("/listBedDetailVoPage")
    public ResultPage<BedDetailVo> listBedDetailVoPage(@ApiParam(name = "page",value = "当前页",required = true) @RequestParam(defaultValue = "1") Integer page,
                                                       @ApiParam(name = "pageSize",value = "每页条数",required = true)@RequestParam(defaultValue = "10") Integer pageSize,
                                                       @ApiParam(name = "customerName",value = "客户名")String customerName,
                                                       @ApiParam(name = "startDate",value = "开始时间")String startDate,
                                                       @ApiParam(name = "endDate",value = "结束时间")String endDate,
                                                       @ApiParam(name = "isDelete",value = "床位状态")Integer isDeleted){
        return bedDetailService.listBedDetailVoPage(page,pageSize,customerName,startDate,endDate,isDeleted);
    }


    @DeleteMapping("/delBedDetails")
    @ApiOperation("根据id删除床位详情")
    public Result delBedDetails(@ApiParam(name = "id",value = "床位详情id",required = true) Integer id){
        bedDetailService.removeById(id);
        return Result.success();
    }


    @PutMapping("/updateBedDetails")
    @ApiOperation("更新床位使用详情，只能修改结束时间")
    public Result updateBedDetails(@RequestBody BedDetails bedDetails){
        BedDetails bedDetails1 = new BedDetails();
        bedDetails1.setId(bedDetails.getId());
        bedDetails1.setEndDate(bedDetails.getEndDate());
        bedDetailService.updateById(bedDetails1);
        return Result.success();
    }

    @PutMapping("/exchangeBed")
    @ApiOperation("变更床位")
    public Result exchangeBed(@RequestBody BedDetailsDto bedDetailsDto) throws ParseException {

        bedDetailService.exchangeBed(bedDetailsDto);

        return Result.success();
    }
}
